package com.qf.agro.web.controller;

import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.ResultInfo;
import com.qf.agro.pojo.SysModule;
import com.qf.agro.pojo.SysRole;
import com.qf.agro.service.SysModuleService;
import com.qf.agro.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ProjectName: smart-agriculture-parent
 * ClassName: SysRoleController
 * Author: chenyaosen
 * Date: 2023/7/3 11:55
 * Description:
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

    @Autowired
    private SysRoleService roleService;

    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize, String name) {
        Page<SysRole> page = roleService.findPage(pageNum, pageSize, name);
        return ResultInfo.success(page);
    }

    @PostMapping
    public ResultInfo save(@RequestBody SysRole sysRole) {
        roleService.save(sysRole);
        return ResultInfo.success(null);
    }

    @PutMapping
    public ResultInfo update(@RequestBody SysRole sysRole) {
        roleService.update(sysRole);
        return ResultInfo.success(null);
    }

    @DeleteMapping
    public ResultInfo delete(Long id) {
        roleService.delete(id);
        return ResultInfo.success(null);
    }

    @GetMapping("/list")
    public ResultInfo findList() {
        List<SysRole> list = roleService.findList();
        return ResultInfo.success(list);
    }

    @GetMapping("/userRole")
    public ResultInfo findUserRole(Long userId) {
        List<Long> roleIds = roleService.findUserRole(userId);
        return ResultInfo.success(roleIds);
    }

}
